#!/usr/bin/python
# -*- coding: UTF-8 -*-
"""
@author:stone
@file:gitlab.py
@time:2021/08/12
"""
from common.config import Config

from common.net import Net


# gitlab 接口不稳定，难以获取数据
# curl -i --header "PRIVATE-TOKEN: mCg83wkUcjpa7pADzvuJ" "https://gitlab.com/api/v4/search?page=200&per_page=100&scope=projects&search=hyperledger"
class Gitlab:
    conf = None

    def __init__(self):
        self.conf = Config()

    def getRepoBySearch(self, query_word, scope, page, per_page, order):
        auth = self.conf.gitlab_token
        headers = {"PRIVATE-TOKEN": auth}

        query_word = "search=" + query_word
        scope = "scope=" + scope
        page = "page=" + page
        per_page = "per_page=" + per_page
        url = "https://gitlab.com/api/v4/search"
        url += "?" + query_word
        url += "&" + scope
        url += "&" + page
        url += "&" + per_page

        # url = """https://gitlab.com/api/v4/search?search=hyperledger&scope=projects&page=1&per_page=100&access_token=KyFJyPYjx45y-j-SrKm6"""
        n = Net()
        return n.send(url, headers, "get", "")
